home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Behaviors / Actions / Set Text / Set Text of Frame.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  4.0 KB  |  133 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS VARS *****************
  4.  
  5. var helpDoc = MM.HELP_behSetTextOfFrame;
  6.  
  7. //******************* BEHAVIOR FUNCTION **********************
  8.  
  9. //Passed a frame references and a string, replaces frame HTML
  10. //If the preserveBg flag is set, preserves BGCOLOR and TEXT attributes.
  11.  
  12. function MM_setTextOfFrame(frameRef,newHTML,preserveBg) { //v3.0
  13.   var bodyAttr="", frameObj=eval(frameRef);
  14.   if (frameObj) with (frameObj.document) { //if frame found
  15.     if (preserveBg) bodyAttr = " BGCOLOR='"+bgColor+"' TEXT='"+fgColor+"'";
  16.     write("<HTML><BODY"+bodyAttr+">"+unescape(newHTML)+"</BODY></HTML>");
  17.     close();
  18.   }
  19. }
  20.  
  21.  
  22. //******************* API **********************
  23.  
  24.  
  25. //Can be used with any tag and any event
  26.  
  27. function canAcceptBehavior(){
  28.   var retVal = false;
  29.   var nameArray = getObjectRefs("NS 4.0","parent","FRAME");  //get frame names
  30.   if (nameArray.length > 0) retVal = "onMouseOver,(onMouseOver),onClick,(onClick)";
  31.   return retVal;
  32. }
  33.  
  34.  
  35.  
  36. //Returns a Javascript function to be inserted in HTML head with script tags.
  37.  
  38. function behaviorFunction(){
  39.   return "MM_setTextOfFrame";
  40. }
  41.  
  42.  
  43.  
  44. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  45. //Calls escQuotes to find embedded quotes and precede them with \
  46.  
  47. function applyBehavior() {
  48.   var index,frameObj,presBg,msgStr="",retVal="";
  49.   with (document.theForm) {
  50.     index = menu.selectedIndex;
  51.     frameObj = escQuotes(document.MM_FRAME_REFS[index]); //get frame name from list
  52.     msgStr = message.value.replace(/[^\x00]*\<html\>\s*([^\x00]*)\s*\<\/html\>[^\x00]*/i,"$1"); //remove any HTML tags
  53.     msgStr = escExprStr(msgStr,true);
  54.     presBg = preserveBg.checked;
  55.   }
  56.   if (frameObj.indexOf(REF_UNNAMED) == 0) retVal = MSG_UnnamedFrame;
  57.   else if (msgStr == null) retVal = MSG_BadBraces;
  58.   else retVal = "MM_setTextOfFrame('"+frameObj+"','"+msgStr+"',"+presBg+")";
  59.   return retVal
  60. }
  61.  
  62.  
  63.  
  64. //Passed the function call above, takes prior arguments and reloads the UI.
  65. //Removes any escape characters "\"
  66.  
  67. function inspectBehavior(fnStr){
  68.   var argArray,found,numLayers,i;
  69.   var frameObj,startStr,endStr,msgStr;
  70.  
  71.   argArray = extractExprStr(fnStr);
  72.   if (argArray.length == 3) { //expect 3 args
  73.     frameObj=argArray[0];
  74.     found = false;
  75.     numLayers = document.MM_FRAME_REFS.length;
  76.     for (i=0; i<numLayers; i++){  //check if frame is in menu
  77.       if (document.MM_FRAME_REFS[i] == frameObj) { //if frame there
  78.         document.theForm.menu.selectedIndex = i;
  79.         found = true;
  80.         break;
  81.       }
  82.     }
  83.     if (!found) alert(errMsg(MSG_FrameNotFound,frameObj));
  84.  
  85.     //set text, converting all string expressions to {expression} etc.
  86.     document.theForm.message.value = unescExprStr(argArray[1],true);
  87.  
  88.     document.theForm.preserveBg.checked = eval(argArray[2]); //check "preserve background" checkbox
  89.   }
  90. }
  91.  
  92.  
  93.  
  94. //***************** LOCAL FUNCTIONS  ******************
  95.  
  96.  
  97. //Load up the frames, set the insertion point
  98.  
  99. function initializeUI(){
  100.   var i,frameObjArray;
  101.  
  102.   frameObjArray  = getObjectRefs("NS 4.0","parent","FRAME"); //get frame refs (IE is same)
  103.  
  104.   //fix unnamed frames to be numbered
  105.   for (i=0; i<frameObjArray.length; i++){
  106.     if (frameObjArray[i].indexOf(REF_UNNAMED) == 0)
  107.       frameObjArray[i] = "parent.frames["+i+"]";
  108.   }
  109.   
  110.   document.MM_FRAME_REFS = frameObjArray; //store frame refs for later
  111.   frameObjArray = niceNames(frameObjArray,TYPE_Frame);  //convert to nice
  112.   for (i=0; i<frameObjArray.length; i++){
  113.     document.theForm.menu.options[i]=new Option(frameObjArray[i]); //add frames to menu
  114.   }
  115.  
  116.   //Select the second frame
  117.   document.theForm.menu.selectedIndex = 1;
  118.  
  119.   document.theForm.message.focus(); //set focus on textbox
  120.   document.theForm.message.select(); //set insertion point into textbox
  121. }
  122.  
  123.  
  124.  
  125. //Gets the BODY HTML from the selected frame and loads it into the textarea.
  126.  
  127. function loadFrameContent() {
  128.   itemNum = document.theForm.menu.selectedIndex;
  129.   var DOM = dreamweaver.getDocumentDOM("parent.frames["+itemNum+"]");
  130.   var theBody = stripSpaces(DOM.body.innerHTML);
  131.   document.theForm.message.value = theBody;
  132. }
  133.